var avatarUp0 = "",avatarUp1 = "";
function iconTypeChange() {
    avatarUp0 = new $IconUpload("avatar0");
    avatarUp0.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
}

$(document).on('click', '.cp_img_delete', function () {
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/pointReword/delteCancel",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});

$("#ensure").click(function () {
    var params = {
        productName: $("#productName").val(),
        productPrice: $("#productPrice").val(),
        productDescription: $("#productDescription").val(),
        putawayNumber: $("#putawayNumber").val(),
        marketPrice: $("#marketPrice").val(),
        type: $("#type").val(),
        remarks: $("#remarks").val(),
        num :$("#num").val(),
        number:$("#number").val(),
        area:$("#area").val()
    };
    if($("#productName").val() == "" || $("#productPrice").val() == "" || $("#productDescription").val() == "" || $("#putawayNumber").val() == "" || $("#marketPrice").val() == ""|| $("#number").val() == ""|| $("#area").val() == ""){
        Feng.error("请补全信息！");return;
    }
    if ($("#avatar0PreId").children().length <= 0) {
        Feng.error("请上传图片！");return;
    }else if($("#avatar0PreId").children().length > 1){
        Feng.error("商品只能上传一张图片，如需要，请在详情去编辑！");return;
    }
    $.ajax({
        url: Feng.ctxPath + "/pointReword/add", type: "post", data: params, success: function (data) {
            Feng.success('操作成功!');
            window.parent.PointReword.table.refresh();
            $("#cancel").click();
        }, error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

$("#updateSure").click(function () {
    var params = {
        productName: $("#productName1").val(),
        productPrice: $("#productPrice1").val(),
        productDescription: $("#productDescription1").val(),
        putawayNumber: $("#putawayNumber1").val(),
        marketPrice: $("#marketPrice1").val(),
        type: $("#type1").val(),
        remarks: $("#remarks1").val(),
        id :$("#id").val(),
        num :$("#num").val(),
        number :$("#number").val()
    };
    if($("#productName1").val() == "" || $("#productPrice1").val() == "" || $("#productDescription1").val() == "" || $("#putawayNumber1").val() == "" || $("#marketPrice1").val() == "" || $("#number").val() == ""  ){
        Feng.error("请补全信息！");return;
    }
    if ($("#avatar0PreId").children().length <= 0) {
        Feng.error("请上传图片！");return;
    }else if($("#avatar0PreId").children().length > 1){
        Feng.error("商品只能上传一张图片，如需要，请在详情去编辑！");return;
    }
    $.ajax({
        url: Feng.ctxPath + "/pointReword/updatePoint", type: "post", data: params, success: function (data) {
            Feng.success('操作成功!');
            window.parent.PointReword.table.refresh();
            $("#cancel").click();
        }, error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

$("#detailsSure").click(function () {
    var params = {
        particulars: $("#describe").val(),
        id :$("#id").val(),
        num :$("#num").val()
    };
    $.ajax({
        url: Feng.ctxPath + "/pointReword/update", type: "post", data: params, success: function (data) {
            Feng.success('操作成功!');
            window.parent.PointReword.table.refresh();
            $("#cancel").click();
        }, error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

$("#cancel").click(function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name))
});

$(function () {
    iconTypeChange();
});